{% extends "base.html" %}

{% block title %}Manage Subusers{% endblock %}

{% block servername %}
<ul class="nav navbar-nav">
	<li class="active dynUpdate" id="{{ server.id }}"><a><i id="applyUpdate" class="fa fa-circle-o-notch fa-spinner fa-spin"></i> {{ server.name }}</a></li>
</ul>
{% endblock %}

{% block sidebar %}
<div class="list-group">
	<a href="#" class="list-group-item list-group-item-heading"><strong>{{ lang.sidebar_acc_actions }}</strong></a>
	<a href="../../account.php" class="list-group-item">{{ lang.sidebar_settings }}</a>
	<a href="../../totp.php" class="list-group-item">TOTP {{ lang.sidebar_settings }}</a>
	<a href="../../servers.php" class="list-group-item">{{ lang.sidebar_servers }}</a>
</div>
<div class="list-group">
	<a href="#" class="list-group-item list-group-item-heading"><strong>{{ lang.sidebar_server_acc }}</strong></a>
	<a href="../index.php" class="list-group-item">{{ lang.sidebar_overview }}</a>
	<a href="../files/index.php" class="list-group-item">{{ lang.sidebar_files }}</a>
	{% if permission.users.view == true %}<a href="list.php" class="list-group-item active">Manage Subusers</a>{% endif %}
	<a href="../settings.php" class="list-group-item">{{ lang.sidebar_manage }}</a>
	<a href="../plugins/index.php" class="list-group-item">{{ lang.sidebar_plugins }}</a>
</div>
{% endblock %}

{% block content %}
<div class="col-9">
	{% if allow_subusers == 1 %}
		<p style="text-align:right;"><a href="add.php"><button class="btn btn-sm btn-primary">Add Subuser</button></a></p>
		{% if get.success %}
			<div class="alert alert-success">You have successfully added a new subuser. They will need to confirm this before they have access to their account. Mistake? Simply click "revoke" next to their name below.</div>
		{% endif %}
		{% if get.revoked %}
			<div class="alert alert-success">You have revoked permission for the selected account.</div>
		{% endif %}
		{% if get.error %}
			<div class="alert alert-danger">Wowza! Thats an error, you seem to have done something that isn't allowed.</div>
		{% endif %}
		<div class="list-group">
		{% for email, info in users %}
			<a href="{% if info.status == "pending" %}#pending{% else %}view.php?id={{ info.id }}{% endif %}" class="list-group-item">
				<h4 class="list-group-item-heading">{{ email }} {% if info.status == "pending" %}<small>(Pending | <span style="cursor:pointer;" onclick="location.href='post/revoke.php?id={{ info.revoke }}';">Revoke</span>)</small>{% endif %}</h4>
				<p class="list-group-item-text"><strong>Permission Nodes:</strong>
					{% for id, perms in info.permissions %}
						{{ perms }}{% if loop.last != true %},{% endif %}
					{% endfor %}
				</p>
			</a>
		{% endfor %}
		</div>
	{% else %}
		<div class="alert alert-danger">This function has not been enabled by your host.</div>
	{% endif %}
</div>
{% endblock %}